<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Block</title>

</head>

<body>
<?php
error_reporting(E_ERROR | E_PARSE);
include('header.php');
include('menu.php');
include("../connection/connection.php");
//include("reportFunctions.php");
$distId=$_SESSION['district'];
//$distId=390;//$_REQUEST['distId'];
$sqlBlockName="select distinct block_id,block_name from tbl_lookup_location where district_id='$distId' order by block_id";
//echo $sqlBlockName;
$queryBlockName=mysql_query($sqlBlockName);
function getStatusNo($distId,$blockId,$status)
{
	if($status=="operation")
	{
		$sqlReport="SELECT count(source) as sourceCount FROM tbl_dtls_q1_main main,tbl_dtls_q1_sws sws where district_id= ".$distId." and block_id=".$blockId." and main.id=sws.loc_id and source like 'Tube-Well%' and current_status='".$status."'";
		//echo $sqlReport;
	}
	else
	{
		$sqlReport="SELECT count(source) as sourceCount FROM tbl_dtls_q1_main main,tbl_dtls_q1_sws sws where district_id= ".$distId." and block_id=".$blockId." and main.id=sws.loc_id and source like 'Tube-Well%'";
		//echo $sqlReport;
	}
	
	$queryReport = mysql_query($sqlReport);
	$rowReport=mysql_fetch_row($queryReport);
	return $rowReport[0];
}

?>
<!--
<table width="1040" border="1">
  <tr>
    <td width="40">Si No</td>
    <td width="19">Id</td>
    <td width="72">District Id </td>
    <td width="64">Block Id </td>
    <td width="63">Village Id </td>
    <td width="60">Scheme</td>
    <td width="48">Source</td>
    <td width="72">Yield Min </td>
    <td width="76">Yield Max </td>
    <td width="121">Water Table Min </td>
    <td width="125">Water Table Max </td>
    <td width="98">Current status </td>
    <td width="100">actual Power </td>
	<td width="100">Power Rating </td>
	<td width="100">Efficiency </td>
    
  </tr>-->
  <?php
  function showEfficiency($distId,$blockId){
$qry="SELECT main.id,district_id,block_id,village_id,type_scheme,no_sources,source,yield_min,yield_max,water_table_min,water_table_max,current_status FROM tbl_dtls_q1_main main,tbl_dtls_q1_sws sws where district_id=".$distId." and main.id=sws.loc_id and source='Tube-Well' and current_status='operation' and block_id=".$blockId."";
//echo $qry;
$rec=mysql_query($qry);
$qryPower="SELECT * FROM tbl_dtls_q1_main main,tbl_dtls_q1_asset asset where district_id=".$distId." and main.id=asset.loc_id and asset_id like 'Sub%' and asset_status='operational' and block_id=".$blockId."";
$recPower=mysql_query($qryPower);
//echo $qryPower;
  $i=1;
  $count1=0;
  $count2=0;
  $count3=0;
  $count4=0;
  $count5=0;
  $total1=0;
  $total2=0;
  $total3=0;
  $total4=0;
  $total5=0;

  while($list=mysql_fetch_array($rec)){
  $rowPower=mysql_fetch_array($recPower);
  $id=$list['id'];
  $asset_power=$rowPower['asset_power'];
  $water_table_max=$list['water_table_max'];
  $yield_min=$list['yield_min'];
  if($list['type_scheme']=="P&T")
  {
  	$sch= 10;
  }
  if($list['type_scheme']=="Piped")
  {
  	$sch= 30;
  }
  if($list['type_scheme']=="RWSS")
  {
  	$sch= 30;
  }
  
  //echo "Scheme".$sch;
  $actual_power= (($water_table_max + $sch) * $yield_min/3.6)/(75 * 0.5);
  //echo "actual Power".$actual_power;
  $efficiency=@($actual_power/$asset_power)*100;
  
  if($efficiency<25)
  {
  	$count1++;
  }
  if($efficiency>25 and $efficiency<50)
  {
  	$count2++;
  }
  if($efficiency>50 and $efficiency<75)
  {
  	$count3++;
  }
  if($efficiency>75 and $efficiency<90)
  {
  	$count4++;
  }
  if($efficiency>90)
  {
  	$count5++;
  }
  
} 
  $arrEffPer['col1']=$count1;
  $arrEffPer['col2']=$count2;
  $arrEffPer['col3']=$count3;
  $arrEffPer['col4']=$count4;
  $arrEffPer['col5']=$count5;
  return $arrEffPer;
  }?>
  <!--
  <tr>
    <td><?php echo $i++;?></td>
    <td><?php echo $list['id'];?></td>
    <td><?php echo $list['district_id'];?></td>
    <td><?php echo $list['block_id'];?></td>
    <td><?php echo $list['village_id'];?></td>
    <td><?php echo $list['type_scheme'];?></td>
    <td><?php echo $list['source'];?></td>
    <td><?php echo $list['yield_min'];?></td>
    <td><?php echo $list['yield_max'];?></td>
    <td><?php echo $list['water_table_min'];?></td>
    <td><?php echo $list['water_table_max'];?></td>
    <td><?php echo $list['current_status'];?></td>
    <td><?php echo $actual_power;?></td>
	    <td><?php echo $asset_power;?></td>
		    <td><?php echo $efficiency;?></td>
			
  </tr>
</table>-->

<table border="0" width="800" cellspacing="0" cellpadding="0">
	<tr>
		<td bgcolor="#E9E9E9" height="26">
		<p align="center">
		<font face="Verdana" style="font-size: 9pt; font-weight: 700" color="#224568">
		Abstract of Efficiency of TWs</font></td>
	</tr>
	<tr>
	  <td bgcolor="#E9E9E9" height="26"><div align="center"><font face="Verdana" style="font-size: 9pt; font-weight: 700" color="#224568">&nbsp;</font> </div></td>
  </tr>
	<tr>
		<td bgcolor="#E9E9E9" height="56">
		<table border="1" width="800" cellspacing="0" cellpadding="0" height="49" bgcolor="#C5D8EB">
			<tr>
				<td width="57" rowspan="2" align="center">
			  <p align="center"><font face="Verdana" style="font-size: 8.5pt" color="#000000">SI No.</font></td>
				<td width="130" rowspan="2" align="center">
				<font face="Verdana" style="font-size: 8.5pt" color="#000000">Name of the Block </font></td>
				<td width="122" rowspan="2" align="center">
			  <p align="center"><font face="Verdana" style="font-size: 8.5pt" color="#000000">No. of Pumps Installed(No.)</font></td>
				<td width="122" rowspan="2" align="center"><font face="Verdana" style="font-size: 8.5pt" color="#000000">No. of Working Pumps(No.)</font></td>
				<td colspan="5" align="center">
				<p align="center"><font face="Verdana" style="font-size: 8.5pt" color="#000000">
				No. of TWs working with Power Efficiency as compared to Design Efficiency</font></td>
			</tr>
			<tr>
				<td align="center" width="78">
				<font style="font-size: 8.5pt" face="Verdana" color="#000000"><25%</font></td>
				<td align="center" width="94">
				<font style="font-size: 8.5pt" face="Verdana" color="#000000">25% to 50%</font></td>
				<td align="center" width="97">
				<font style="font-size: 8.5pt" face="Verdana" color="#000000">50% to 75%</font></td>
				<td align="center" width="96">
				<font style="font-size: 8.5pt" face="Verdana" color="#000000">75% to 90%</font></td>
				<td align="center" width="119">
				<font style="font-size: 8.5pt" face="Verdana" color="#000000">90% to 100%</font></td>
			</tr>
		
			<?php
			$totalOperational=0;
			$totalPumpNo=0;
			$i=1;
			while($rowBlockName = mysql_fetch_array($queryBlockName)) {
			 $totalPump=getStatusNo($distId,$rowBlockName['block_id'],'');
			 $operation=getStatusNo($distId,$rowBlockName['block_id'],'operation');
			 $totalPumpNo +=$totalPump;
			 $totalOperational +=$operation;
			 $Efficiency=showEfficiency($distId,$rowBlockName['block_id']);
			$totalCol1+=$Efficiency['col1'];
			$totalCol2+=$Efficiency['col2'];
			$totalCol3+=$Efficiency['col3'];
			$totalCol4+=$Efficiency['col4'];
			$totalCol5+=$Efficiency['col5'];
			?><tr><td width='57' align='center'><font style="font-size: 8.5pt" face="Verdana" color="#000000"><?php echo $i++;?></font></td>
				<td width='130' align='center'><font style="font-size: 8.5pt" face="Verdana" color="#000000"><?php echo $rowBlockName['block_name'];?></font></td>
				<td width='122' align='center'><font style="font-size: 8.5pt" face="Verdana" color="#000000"><?php echo   $totalPump;?></font></td>
				<td width='122' align='center'><font style="font-size: 8.5pt" face="Verdana" color="#000000"><?php echo $operation; ?></font></td>
				<td align='center' width='78'><font style="font-size: 8.5pt" face="Verdana" color="#000000"><?php echo $Efficiency['col1'];?></font></td>
				<td align='center' width='94'><font style="font-size: 8.5pt" face="Verdana" color="#000000"><?php echo $Efficiency['col2'];?></font></td>
				<td width="97" align='center'><font style="font-size: 8.5pt" face="Verdana" color="#000000"><?php echo $Efficiency['col3'];?></font></td>
				<td align='center' width='96'><font style="font-size: 8.5pt" face="Verdana" color="#000000"><?php echo $Efficiency['col4'];?></font></td>
			    <td align='center' width='119'><font style="font-size: 8.5pt" face="Verdana" color="#000000"><?php echo $Efficiency['col5'];?></font></td>
			</tr>
			<?php
			
			}
			?>
			<tr>
			  <td colspan="2" align='center' bgcolor="#f9f9f9"><font style="font-size: 9.5pt" face="Verdana" color="#000000">Total Pump </font></td>
			<td width='122' align='center' bgcolor="#f9f9f9"><font style="font-size: 9.5pt" face="Verdana" color="#000000"><?php echo $totalPumpNo;?></font></td>
			  <td width='122' align='center' bgcolor="#f9f9f9"><font style="font-size: 9.5pt" face="Verdana" color="#000000"><?php echo $totalOperational;?></font></td>
				<td align='center' width='78' bgcolor="#f9f9f9"><font style="font-size: 9.5pt" face="Verdana" color="#000000"><?php echo $totalCol1;?></font></td>
				<td align='center' width='94' bgcolor="#f9f9f9"><font style="font-size: 9.5pt" face="Verdana" color="#000000"><?php echo $totalCol2;?></font></td>
				<td align='center' bgcolor="#f9f9f9"><font style="font-size: 9.5pt" face="Verdana" color="#000000"><?php echo $totalCol3;?></font></td>
				<td width='96' align='center' bgcolor="#f9f9f9"><font style="font-size: 9.5pt" face="Verdana" color="#000000"><?php echo $totalCol4;?></font></td>
			    <td width='119' align='center' bgcolor="#f9f9f9"><font style="font-size: 9.5pt" face="Verdana" color="#000000"><?php echo $totalCol5;?></font></td>
			</tr>
		</table>		</td>
	</tr>
</table>
<p>&nbsp;</p>

</body>

</html>